package com.tianyi.learnmachinesdkdemo;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.tianyi.learnmachinesdk.LearnMachineSDK;
import com.tianyi.learnmachinesdk.listener.EventPopupListener;
import com.tianyi.learnmachinesdk.listener.LearnMachineLogListener;
import com.tianyi.learnmachinesdk.utils.LearnMachineCofig;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button apklistBtt;
    private Button logBtt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        apklistBtt = findViewById(R.id.apk_button);
        logBtt = findViewById(R.id.log_button);
        logBtt.setOnClickListener(this);
        apklistBtt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        if (v.getId() == R.id.apk_button) {
            LearnMachineSDK.init(new LearnMachineCofig(this).setEventPopupListener(new EventPopupListener() {
                @Override
                public void onLoadSuccess(String var1) {
                    Log.e("===============>", var1);
                }

                @Override
                public void onLoadFailed(String var1, int var3) {
                    Log.e("===============>", var1);
                    Log.e("===============>", "code:" + var3);
                }
            }).loadApkList().setActivity(this));
        } else if (v.getId() == R.id.log_button) {
            Map<String, String> map = new HashMap<>();
            map.put("et", "");
            map.put("ev", "{" +
                    "      id : SN序列号," +
                    "      model : iPhone X," +
                    "      session_id :  1," +
                    "      ..." +
                    "    }");
            LearnMachineSDK.setLearnMachineCofig(map, this, new LearnMachineLogListener() {
                @Override
                public void onAddLogFailed(String vr1) {
                    Log.e("============>", vr1);
                }
            });
        }
    }

}